package com.inspur.cmis.controller;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.inspur.cmis.service.UserService;
import com.inspur.cmis.pojo.User;

@Controller
public class LoginController {
	@Autowired
	private UserService userService;
	/**
	 * 登录方法
	 * 
	 * @param username
	 * @param password
	 * @return
	 */
	@RequestMapping("/loginController")
	public ModelAndView login(User user,HttpSession session) {
		ModelAndView mv = new ModelAndView();
		User checkUser = null;
		if(null != user){
			 checkUser = userService.getUser(user);
			System.out.println("================="+ user.getRoleId());
		}
		if (null != checkUser) {
			mv.addObject("success", "恭喜你，登录成功");
			//mv.addObject("user",checkUser );
			session.setAttribute("user", checkUser);
			mv.setViewName("main.jsp");
		} else {
			mv.addObject("error", "用户名密码错误，请重新登录！");
			mv.setViewName("login.jsp");
		}
		return mv;
	}

}